Con log:"Init" from:"StringBuffer".
Repl newClass:"StringBufferClass".
StringBufferClass setParent: XClass.
(StringBufferClass new) setName:"StringBuffer".
StringBuffer addField:"array".
StringBuffer addField:"used".

Repl methodIn: StringBuffer.
initialize[
   array <- Array new: 100.
   used <- 0.
]

Repl methodIn: StringBuffer.
append: str[
   len <- used + (str length).
   self ensureLength: len.
   (Range from: 0 to: (str length)) do:[i:||
      array at: used set:(str at:i).
      used <- used+1.
      ^null.
   ]
]

Repl methodIn: StringBuffer.
toString[
   ^array toStringAsByteArrayFrom:0 to: used.
]

Repl methodIn: StringBuffer.
ensureLength: len[
   (len > (array length))
      ifTrue:[|| array <- (array resize: (len+100)) ]
      else:[|| self ].
]
